package com.module.regrole
{
	import com.connect.agreement.mclgc.Packet;
	import com.game.Global;
	import com.game.commands.EnterGameCommand;
	import com.game.views.RegRoleMediator;
	
	import mx.controls.Alert;
	import mx.utils.ObjectProxy;
	
	import org.phprpc.util.PHPSerializer;
	import org.puremvc.as3.patterns.facade.Facade;
	

	public class RegRoleManager
	{
		public static const GetRoleList:int = 1;
		public static const CreateRole:int = 2;
		public static const DeleteRole:int = 3;
		public static const Failed:int = 4;
		public static const EnterGame:int = 5;
		
		public static var rolereg:RoleReg;
		
		public static var instance:RegRoleManager = new RegRoleManager();
		
		public function RegRoleManager()
		{
		}
		
		public function update(packet:Packet):void
		{
			if(packet==null)
				return;
			switch(packet.cmd)
			{
				case GetRoleList:
					var list:Array = PHPSerializer.unserialize(packet.data);
					if(list.length == 0){
						Facade.getInstance().sendNotification(RegRoleMediator.CREATEROLE);
					} else {
						Facade.getInstance().sendNotification(RegRoleMediator.SHOWROLES,list);
					}
					break;
				case CreateRole:
					
					break;
				case DeleteRole:
					
					break;
				case Failed:
					Alert.show(PHPSerializer.unserialize(packet.data));
					break;
				case EnterGame:
					Global.ctrlrole = new ObjectProxy(PHPSerializer.unserialize(packet.data));
					trace(Global.ctrlrole.name + " 进入游戏……");
					Facade.getInstance().sendNotification(EnterGameCommand.NAME);
					break;
			}
		}
	}
}